package com.xinzhang;

import java.util.List;

import com.asy.ui.base.ImageAndText;
import com.asy.ui.base.ImageAndTextListAdapter;
import com.helper.SqlLiteHepler;
import com.xinzhang.base.BaseActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class mapimagelist extends BaseActivity implements OnClickListener {

	private Animation Anim_Alpha; 
	
	private ImageView dbback;
	
	private ListView listView;
	
	private List<ImageAndText> list;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.maplist);
		BaseApp myApp  = (BaseApp)getApplication();
		list=myApp.getImageList();
		
		SqlLiteHepler sqlLiteHepler=new SqlLiteHepler(this);
		sqlLiteHepler.DeleteFocusImages(3);
		sqlLiteHepler.Close();
		
		
		listView=(ListView)findViewById(R.id.map_listview);
		dbback=(ImageView)findViewById(R.id.dbtnback);
		dbback.setOnClickListener(this);
		Anim_Alpha = AnimationUtils.loadAnimation(this, R.anim.alpha_action);  
		
		final ImageAndTextListAdapter  ImageAndTextListAdapter=new ImageAndTextListAdapter(this,list,listView);
		listView.setAdapter(ImageAndTextListAdapter);
		
		
		sqlLiteHepler=new SqlLiteHepler(this);
		sqlLiteHepler.BatchInsertFocusImages(list,3);
		sqlLiteHepler.Close();
		
		listView.setOnItemClickListener(new OnItemClickListener() {  
            public void onItemClick(AdapterView<?> arg0, View arg1,
         		int arg2, long arg3) {
              Intent intent=new Intent(mapimagelist.this,imagedetail.class);
              Bundle mBundle = new Bundle();
              mBundle.putInt("imageandtext", arg2);
              mBundle.putInt("selindex", 3);
              intent.putExtras(mBundle);
              startActivity(intent);
            }
         });
	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
		v.startAnimation(Anim_Alpha);
		if(v.getId()==R.id.dbtnback)
		{
			finish();
		}
		
	}
}
